package cn.tedu.luban.worker.main.controller;

import cn.tedu.luban.worker.main.converter.WorkerAuditConverter;
import cn.tedu.luban.worker.main.converter.WorkerConverter;
import cn.tedu.luban.worker.main.service.WorkerService;
import cn.tedu.luban.worker.protocol.VO.AdminAuditDetailVO;
import cn.tedu.luban.worker.protocol.VO.AdminWorkerListVO;
import cn.tedu.luban.worker.protocol.bo.AdminWorkerBO;
import cn.tedu.luban.worker.protocol.param.AuditSubmitParam;
import cn.tedu.luban.worker.protocol.query.WorkerListQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import com.tedu.inn.protocol.pager.PagerResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 专门处理后台管理的师傅接口
 *
 * 审核列表
 * 审核详情
 * 审核提交
 */

@RestController
@Slf4j
public class WorkerAdminController {

    @Autowired
    private WorkerConverter workerConverter;

    @Autowired
    private WorkerService workerService;

    @Autowired
    private WorkerAuditConverter workerAuditConverter;


    @PostMapping("/admin/worker/aduit")
    public Result<PagerResult<AdminWorkerListVO>> auditListWorkers (@RequestBody WorkerListQuery workerListQuery)
            throws BusinessException {
        //1.分页对象 5个属性 中的 list 和total
        ListRecordTotalBO<AdminWorkerBO> listBOS=workerService.auditListWorkerTotal(workerListQuery);
        //2.对象转换 将bos对象转换成PagerResult对象
        PagerResult<AdminWorkerListVO> adminWorkerListVOPagerResult = workerConverter.bo2PagerResultVO(listBOS, workerListQuery);
        return new Result<>(adminWorkerListVOPagerResult);
    }

    @PostMapping("/admin/worker/audit/detail")
    public Result<AdminAuditDetailVO> auditDetail(@RequestParam("workerId")Long userId) throws BusinessException{
        //1.业务层出参 AdminWorkerBO
        AdminWorkerBO adminWorkerBO=workerService.auditDetail(userId);
        //2.控制转换AdminAuditDetailVO
        AdminAuditDetailVO adminAuditDetailVO = workerAuditConverter.bo2vo(adminWorkerBO);
        return new Result<>(adminAuditDetailVO);

    }

    @PostMapping("/admin/worker/audit/save")
    public Result<Long> auditSumbit(@RequestBody AuditSubmitParam auditSubmitParam) throws BusinessException {
        //1.调用业务层 处理业务 返回auditId
        Long auditId=workerService.auditSumbit(auditSubmitParam);
        //2.通过Result返回结果
        return new Result<>(auditId);
    }
}
